// pages/Burstrate/index.js
//,"pageOrientation": "landscape"
const db = wx.cloud.database();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        holyrelic: [{
                text: '圣遗物',
                value: 0
            },
            {
                text: '魔女',
                value: 1
            },
            {
                text: '渡火',
                value: 2
            },
        ],
        parts: [{
                text: '部位',
                value: 'a'
            },
            {
                text: '花',
                value: 'b'
            },
            {
                text: '羽',
                value: 'c'
            },
            {
                text: '沙',
                value: 'd'
            },
            {
                text: '杯',
                value: 'e'
            },
            {
                text: '冠',
                value: 'f'
            }
        ],
        attribute1: [{
                text: '属性1',
                value: 'a11'
            },
            {
                text: '生命值',
                value: 'a12'
            },
            {
                text: '攻击力',
                value: 'a13'
            },
            {
                text: '元素精通',
                value: 'a14'
            },
            {
                text: '暴击率',
                value: 'a15'
            },
            {
                text: '暴伤',
                value: 'a16'
            },
            {
                text: '攻百分',
                value: 'a17'
            },
            {
                text: '火',
                value: 'a18'
            },
            {
                text: '雷',
                value: 'a19'
            },
            {
                text: '风',
                value: 'a20'
            },
            {
                text: '岩',
                value: 'a21'
            },
            {
                text: '水',
                value: 'a22'
            },
            {
                text: '物理',
                value: 'a23'
            },
            {
                text: '冰',
                value: 'a24'
            },
            {
                text: '水',
                value: 'a25'
            },
            {
                text: '元素充能',
                value: 'a26'
            },
            {
                text: '防御',
                value: 'a27'
            },
            {
                text: '防百分',
                value: 'a28'
            },
            {
                text: '生百分',
                value: 'a29'
            }

        ],
        attribute2: [{
                text: '属性2',
                value: 'b11'
            },
            {
                text: '生命值',
                value: 'b12'
            },
            {
                text: '攻击力',
                value: 'b13'
            },
            {
                text: '元素精通',
                value: 'b14'
            },
            {
                text: '暴击率',
                value: 'b15'
            },
            {
                text: '暴伤',
                value: 'b16'
            },
            {
                text: '攻百分',
                value: 'b17'
            },
            {
                text: '火',
                value: 'b18'
            },
            {
                text: '雷',
                value: 'b19'
            },
            {
                text: '风',
                value: 'b20'
            },
            {
                text: '岩',
                value: 'b21'
            },
            {
                text: '水',
                value: 'b22'
            },
            {
                text: '物理',
                value: 'b23'
            },
            {
                text: '冰',
                value: 'b24'
            },
            {
                text: '水',
                value: 'b25'
            },
            {
                text: '元素充能',
                value: 'b26'
            },
            {
                text: '防御',
                value: 'b27'
            },
            {
                text: '防百分',
                value: 'b28'
            },
            {
                text: '生百分',
                value: 'b29'
            }
        ],
        attribute3: [{
                text: '属性3',
                value: 'c11'
            },
            {
                text: '生命值',
                value: 'c12'
            },
            {
                text: '攻击力',
                value: 'c13'
            },
            {
                text: '元素精通',
                value: 'c14'
            },
            {
                text: '暴击率',
                value: 'c15'
            },
            {
                text: '暴伤',
                value: 'c16'
            },
            {
                text: '攻百分',
                value: 'c17'
            },
            {
                text: '火',
                value: 'c18'
            },
            {
                text: '雷',
                value: 'c19'
            },
            {
                text: '风',
                value: 'c20'
            },
            {
                text: '岩',
                value: 'c21'
            },
            {
                text: '水',
                value: 'c22'
            },
            {
                text: '物理',
                value: 'c23'
            },
            {
                text: '冰',
                value: 'c24'
            },
            {
                text: '水',
                value: 'c25'
            },
            {
                text: '元素充能',
                value: 'c26'
            },
            {
                text: '防御',
                value: 'c27'
            },
            {
                text: '防百分',
                value: 'c28'
            },
            {
                text: '生百分',
                value: 'c29'
            }
        ],
        attribute4: [{
                text: '属性4',
                value: 'd11'
            },
            {
                text: '生命值',
                value: 'd12'
            },
            {
                text: '攻击力',
                value: 'd13'
            },
            {
                text: '元素精通',
                value: 'd14'
            },
            {
                text: '暴击率',
                value: 'd15'
            },
            {
                text: '暴伤',
                value: 'd16'
            },
            {
                text: '攻百分',
                value: 'd17'
            },
            {
                text: '火',
                value: 'd18'
            },
            {
                text: '雷',
                value: 'd19'
            },
            {
                text: '风',
                value: 'd20'
            },
            {
                text: '岩',
                value: 'd21'
            },
            {
                text: '水',
                value: 'd22'
            },
            {
                text: '物理',
                value: 'd23'
            },
            {
                text: '冰',
                value: 'd24'
            },
            {
                text: '水',
                value: 'd25'
            },
            {
                text: '元素充能',
                value: 'd26'
            },
            {
                text: '防御',
                value: 'd27'
            },
            {
                text: '防百分',
                value: 'd28'
            },
            {
                text: '生百分',
                value: 'd29'
            }
        ],
        holyrelicval: 0, //圣遗物val
        partsval: 'a', //部位val
        ava1: 'a11', //属性1
        ava2: 'b11', //属性2
        ava3: 'c11', //属性3
        ava4: 'd11', //属性4
        showholy:[],

    },
    sure() {
        let holy = this.data.holyrelicval;
        let part = this.data.partsval;
        let a1 = this.data.ava1
        let b1 = this.data.ava2
        let c1 = this.data.ava3
        let d1 = this.data.ava4
        if (holy != '' && part != '' && a1 != '' && b1 != '' && c1 != '' && d1 != '') {
            db.collection('holyrelic').add({
                data: {
                    holy: holy,
                    part: part,
                    a1: a1,
                    b1: b1,
                    c1: c1,
                    d1: d1
                }, 
                success: (res)=> {
                    wx.showToast({
                        title: '添加成功',
                        icon: 'success',
                        duration: 2000,
                        mask: true
                    })   
                 this.onReady()
                  }
            })
           
        } else {
            wx.showToast({
                title: '失败,不能留空',
                icon: 'none',
                duration: 2000,
                mask: true
            })
        }
       

    },
    getholy() {
        db.collection('holyrelic').get({
            success: (res) => {
                let showgetholy = []
                outer: 
                for (let i = 0; i < res.data.length; i++) {
                    let getholy = res.data[i];
                    for (let j = 0; j < showgetholy.length; j++) {
                        let showholy = showgetholy[j]
                        // console.log(this.data.holyrelic);
                        if (getholy.holy == showholy.holy) {
                            showholy.list.push({
                                part:this.getText(getholy.part,this.data.parts) ,
                                a1: this.getText(getholy.a1,this.data.attribute1),
                                b1:  this.getText(getholy.b1,this.data.attribute2),
                                c1: this.getText(getholy.c1,this.data.attribute3),
                                d1: this.getText(getholy.d1,this.data.attribute4)
                            })
                            continue outer
                        }
                       
                    }
                    showgetholy.push({
                        holy: this.getText(getholy.holy,this.data.holyrelic),
                        list: [{
                            part:this.getText(getholy.part,this.data.parts) ,
                            a1: this.getText(getholy.a1,this.data.attribute1),
                            b1:  this.getText(getholy.b1,this.data.attribute2),
                            c1: this.getText(getholy.c1,this.data.attribute3),
                            d1: this.getText(getholy.d1,this.data.attribute4)
                        }]
                    })
                }
                this.setData({
                    showholy:showgetholy
                })
            }
        })
       
    },
    getText(val,arr){
        //遍历穿进来的数组 判断val是否相等，如果相等就返回text
        let value=''
      arr.forEach(element => {
            if(element.value==val){
                value= element.text
            }
        });
        return value
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getholy()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})